class PostMgrController {

    def index = { }

    def studentInfo = {
        [studentPostList:Post.findAllByStudentIsNotNull(),studentPostCount:Post.countByStudentIsNotNull()]
    }
 

    def delete = {
        def postInstance = Post.get(params.id)
        if (postInstance) {
            try {
                postInstance.delete(flush: true)
                flash.message = "删除成功"
                redirect(action: "studentInfo")
                
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'post.label', default: 'Post'), postInstance])}"
                redirect(action: "studentInfo")
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'post.label', default: 'Post'), params.id])}"
            redirect(action: "studentInfo")
        }
    }

    def update = {
        def postInstance = Post.get(params.id)
        if (postInstance) {
            postInstance.properties = params
            if (!postInstance.hasErrors() && postInstance.save(flush: true)) {
                flash.message = "更新成功"
                redirect(action: "studentInfo",controller:"postMgr")
            }
            else {
                render(view: "edit", model: [postInstance: postInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'post.label', default: 'Post'), params.id])}"
            redirect(action: "studentInfo",controller:"postMgr")
        }
    }


    def search = {
        def c = Post.createCriteria()
        def results = c.list {
                if(params.sex != '0'){
                    eq('needSex',params.needSex)
                }
                order 'id', 'desc'
        }
        def postInstanceList = results.findAll{
                it.courses.any{ aCourse ->
                    aCourse == params.courses
                
                }
        }
        render(view:"list",model:[postInstanceList: postInstanceList,postInstanceListSize:postInstanceList.size()])
        
    }
}
